package com.itzsj.controller;

import com.itzsj.common.result.Result;
import com.itzsj.pojo.entity.Enterprise;
import com.itzsj.pojo.entity.Graduate;
import com.itzsj.pojo.entity.Message;
import com.itzsj.pojo.entity.Work;
import com.itzsj.service.AdminService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/admin")
public class AdminController {

    @Resource
    private AdminService adminService;

    @GetMapping("/list-g")
    public Result listG(String sno, String grade) {
        List<Graduate> graduates = adminService.listG(sno, grade);
        return Result.success(graduates);
    }

    @PutMapping("/update-g")
    public Result updateG(@RequestBody Graduate graduate) {
        adminService.updateG(graduate);
        return Result.success();
    }

    @DeleteMapping("/del-g/{sno}")
    public Result deleteG(@PathVariable("sno") String sno) {
        adminService.deleteG(sno);
        return Result.success();
    }

    @GetMapping("/list-w")
    public Result listW(String sno) {
       List<Work> works =  adminService.listW(sno);
       return Result.success(works);
    }

    @PostMapping("/save-w")
    public Result saveW(@RequestBody Work work) {
        adminService.saveW(work);
        return Result.success();
    }

    @DeleteMapping("/del-w/{sno}")
    public Result deleteW(@PathVariable("sno") String sno) {
        adminService.deleteW(sno);
        return Result.success();
    }

    @GetMapping("/list-e")
    public Result listE(String eno){
        List<Enterprise> list = adminService.listE(eno);
        return Result.success(list);
    }

    @PostMapping("/save-e")
    public Result saveE(@RequestBody Enterprise enterprise) {
        adminService.saveE(enterprise);
        return Result.success();
    }

    @DeleteMapping("/del-e")
    public Result deleteE(String eno){
        adminService.deleteE(eno);
        return Result.success();
    }

    @GetMapping("/list-m")
    public Result listM(String sno) {
        List<Message> list = adminService.listM(sno);
        return Result.success(list);
    }

    @DeleteMapping("/del-m")
    public Result deleteM(@RequestParam("ids") List<Integer> ids){
        adminService.deleteM(ids);
        return Result.success();
    }

}
